import {useState,useEffect} from 'react'

const usePiostion = ()=>{
  const [posions,setPosons] = useState({x:0,y:0})
  useEffect(()=>{
    console.log('add effect',posions.x)
    const updateMosefn = (e:MouseEvent)=>{
      console.log('设置更新位置')
      setPosons({x:e.clientX,y:e.clientY})
    }
    document.addEventListener('mousemove',updateMosefn)
    return ()=>{
      //清除上一次的addEventListener
      console.log('remove effect' ,posions.x)
      document.removeEventListener('mousemove',updateMosefn)
    }
  },[posions])
  return posions

}
export default usePiostion
